{* $Id$ *}
{include_core file="admin/lib/header.html" title="用户展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">合伙人管理</h2>
  </div>
  <div class="search-form js_advancedForm" >
    <form action="user/admin" method="get" class="js_focusSearchForm">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">手机号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_name]" value="{$search_filter.user_name}">
      </p>
      <p>
        <label for="" class="search-f-label">姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[realname]" value="{$search_filter.realname}">
      </p>
      <p>
      <label for="" class="search-f-label">注册时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>

  <!--start:列表-->
<div class="list-table-filters">
    <p>
        <span class="label label-info">按状态</span>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("status", 1)}")}" {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>正常</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("status", 0)}")}" {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已禁用</a>
    </p>
    <p>
        <span class="label label-info">按身份</span>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("role_type", -1)}")}" {if URLTracker::val("role_type") == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("role_type", 1)}")}" {if URLTracker::val("role_type") == 1} class="label label-primary" {else} class="label label-default" {/if}>一级合伙人</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("role_type", 2)}")}" {if URLTracker::val("role_type") == 2} class="label label-primary" {else} class="label label-default" {/if}>二级合伙人</a>
    </p>
    <p>
        <span class="label label-info">抱抱币</span>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_bbcoin_enable", -1)}")}" {if URLTracker::val("is_bbcoin_enable") == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_bbcoin_enable", 0)}")}" {if URLTracker::val("is_bbcoin_enable") == 0} class="label label-primary" {else} class="label label-default" {/if}>抱抱币进货奖励 - 未开启</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_bbcoin_enable", 1)}")}" {if URLTracker::val("is_bbcoin_enable") == 1} class="label label-primary" {else} class="label label-default" {/if}>抱抱币进货奖励 - 已开启</a>
    </p>
    <p>
        <span class="label label-info">开票</span>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_invoice", -1)}")}" {if URLTracker::val("is_invoice") == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_invoice", 1)}")}" {if URLTracker::val("is_invoice") == 1} class="label label-primary" {else} class="label label-default" {/if}>允许</a>
        <a href="{AnUrl("user/admin/dealer?{URLTracker::set("is_invoice", 0)}")}" {if URLTracker::val("is_invoice") == 0} class="label label-primary" {else} class="label label-default" {/if}>不允许</a>
    </p>
</div>

{include_core file="admin/lib/pager.html"}
  <table class="list-table">
    <thead><tr>
      <th style="width:60px;">编号</th>
      <th style="width:60px;">用户名</th>
      <th style="width:60px;">角色</th>
      <!-- <th style="width:60px;">头像</th> -->
      <th style="min-width:300px;">其他信息</th>
      <th style="width:130px;">注册时间</th>
      <th style="width:130px;">状态</th>
      <th>
          {if $status == 1}
          用户余额/积分/抱抱币操作
          {else}
          用户余额/积分/抱抱币
          {/if}
      </th>
      <th style="width:60px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $user_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          <td class="js_userName">{$v.id}</td>
          <td class="js_userName">{$v.user_name}</td>
          <td>{$v.role_type}</td>
          <!-- <td>
              <img width="60" src="{user_helper::avatar($v['id'])}">
          </td> -->
          <td>
            {* 性别：{if $v.gender == 1}男{elseif $v.gender == 0}女{else}未知{/if}<br /> *}
            手机号码：{$v.mobile}<br />
            真实姓名：{$v.realname}<br />
            {if $v.parent_id > 0}
              父级合伙人：<a href="{AnUrl('user/admin')}?search_filter%5Buser_name%5D={$v.parent_user_name}">{$v.parent_user_name}</a><br/>
            {/if}
            {if $v.role_id == user_config::MARKETING}
              合伙人ID：{$v.dealer_info.id}<br />
              合伙人姓名：{if $v.dealer_info.realname}{$v.dealer_info.realname}{else}{$v.dealer_info.nickname}{/if}<br />
              合伙人手机号：{$v.dealer_info.mobile}<br />
            {/if}
          </td>
          <td>{time_format($v.add_time)}</td>
          <td>
              {if $v.status}
              <span class="label label-success">正常</span><br />
              {else}
              <span class="label label-danger">已禁用</span><br />
              {/if}
              {if $v.role_id == user_config::AGENCY}
                {if $v.is_bbcoin_enable > 0}
                   <span class="label label-success">抱币奖</span><br />
                {/if}
              {/if}
              {if $v.is_invoice == 1}
              <span class="label label-success">允许开票</span><br />
              {/if}
          </td>
          <td>
          {if $status == 1}
            {if $v.role_id == user_config::AGENCY}
              <div class="label-btn-group"><span class="label label-info">押金</span><span class="label label-default">{num_keep_two_round($v.deposit_money)}</span><a href="{AnUrl("user_money/admin/deposit_money/add_deposit_money?id={$v.id}&query_string={URLTracker::parse()}")}" class="btn btn-success"><i class="icon-edit icon-white"></i>增加</a></div>
              <div class="label-btn-group"><span class="label label-info">保金</span><span class="label label-default">{num_keep_two_round($v.bargain_money)}</span><a href="{AnUrl("user_money/admin/bargain_money/add_bargain_money?id={$v.id}&query_string={URLTracker::parse()}")}" class="btn btn-success"><i class="icon-edit icon-white"></i>增加</a></div>
            {/if}
            {if $v.role_id == user_config::STORE_MANAGER || $v.role_id == user_config::AGENCY}
              <div class="label-btn-group"><span class="label label-info">余额</span><span class="label label-default">{num_keep_two_round($v.user_money)}</span><a href="{AnUrl("user_money/admin/user_money/add_user_money?id={$v.id}&query_string={URLTracker::parse()}")}" class="btn btn-success"><i class="icon-edit icon-white"></i>增加</a></div>
              <div class="label-btn-group"><span class="label label-warning">积分</span><span class="label label-default">{intval($v.score)}</span><a href="{AnUrl("score_record/admin/add_score?id={$v.id}&query_string={URLTracker::parse()}")}" class="btn btn-success"><i class="icon-edit icon-white"></i>增加</a></div>
              <div class="label-btn-group"><span class="label label-success">抱币</span><span class="label label-default">{intval($v.bbcoin)}</span><a href="{AnUrl("bbcoin/admin/add_bbcoin?id={$v.id}&query_string={URLTracker::parse()}")}" class="btn btn-success"><i class="icon-edit icon-white"></i>增加</a></div>
            {/if}
          {else}
            {if $v.role_id == user_config::AGENCY}
              <span class="label label-default">押金 {num_keep_two_round($v.deposit_money)}</span><br/>
              <span class="label label-default">保金 {num_keep_two_round($v.bargain_money)}</span><br/>
            {/if}
            {if $v.role_id == user_config::STORE_MANAGER || $v.role_id == user_config::AGENCY}
              <span class="label label-default">余额 {num_keep_two_round($v.user_money)}</span><br/>
              <span class="label label-default">积分 {intval($v.score)}</span><br/>
              <span class="label label-default">抱币 {intval($v.bbcoin)}</span><br/>
            {/if}
          {/if}
          </td>
          <td>
              {if $v.role_id == user_config::AREA_MANAGER}
            <a href="{AnUrl("user/admin/area_manager/add?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              {elseif $v.role_id == user_config::DIRECTOR}
              <a href="{AnUrl("user/admin/director/add?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              {elseif $v.role_id == user_config::CINEMA_ASSISTANT}
              <a href="{AnUrl("user/admin/cinema_assistant/add?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              {elseif $v.role_id == user_config::MULTIPLE_DIVISION}
              <a href="{AnUrl("user/admin/multiple/edit?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              {else}
              <a href="{AnUrl("user/admin/edit?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>编辑</a>
              {/if}
            {if $v.role_id == user_config::MULTIPLE_DIVISION}
                <a href="{AnUrl("store/admin?is_multiple=1&multiple_id={$v.id}&query_string={$query_string}")}" class="btn btn-primary btn-xs"><i class="icon-edit icon-white"></i>查看地区门店</a>
            {/if}
            {if $status == 1 && $v.id != 1}
              {if $v.parent_id == 0 && $v.dealer_level == 1}
                <a href="{AnUrl("user/admin/add_second_dealer?id={$v.id}&query_string={$query_string}")}" class="btn btn-success btn-xs"><i class="icon-edit icon-white"></i>增加二级合伙人</a>
                <a url="{AnUrl("user/admin/get_second_dealer_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-primary btn-xs js_showSecondDealer"><i class="icon-edit icon-white"></i>查看子合伙人</a>
              {/if}
              {if $v.dealer_level >= 1}
                <a href="{AnUrl("user/admin/show_area_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-primary btn-xs"><i class="icon-edit icon-white"></i>设置/查看地区</a>
                <a href="{AnUrl("user/admin/show_dealer_address_list?id={$v.id}&query_string={$query_string}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>设置/查看仓库地址</a>
              {/if}
              <a href="{AnUrl("user/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs deleteOne"><i class="icon-trash icon-white"></i>禁用</a>
            {elseif $status == 0}
              <a href="{AnUrl("user/admin/change_status?status=1")}" class="btn btn-success btn-xs changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
              <a href="{AnUrl("user/admin/delete_user?id={$v.id}")}" class="btn btn-danger btn-xs deleteOneUser"><i class="icon-trash icon-white"></i>删除</a>
            {/if}
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="12">暂无数据</td></tr>
      {/foreach}
    </tbody>
  </table>
  <script type="text/javascript">

  $(function(){


      if ('{user_config::AGENCY}' == $('select[name="search_filter[role_id]"]').val()) {
          $('.js_assistant').show();
      } else {
          $('.js_assistant').hide();
          $('select[name="assistant_user_id"]').val('0');
      }

      $('select[name="search_filter[role_id]"]').change(function(){
          if ('{user_config::AGENCY}' == $(this).val()) {
              $('.js_assistant').show();
          } else {
              $('.js_assistant').hide();
              $('select[name="assistant_user_id"]').val('0');
          }
      });


   // 将制定的元素设置为可是区域居中
      function center_format(obj){
          // 获取可是窗口的宽度
          var winWidth  = $(window).width();
          var winHeight = $(window).height();

          // 计算窗体本身的宽和高
          var objWidth = obj.width();
          var objHeight = obj.height();

          // 设置窗体的位置
          obj.css('position', 'fixed');
          // 计算left和top值
          var objLeft = (winWidth - objWidth)/2;
          var objTop = (winHeight - objHeight)/3; // 如果除以2感觉不垂直居中
          obj.css('left', objLeft+'px');
          obj.css('top', objTop+'px');

      }

    // 高级搜索
    $('.js_advanced').click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var outBox  = thisObj.closest('form');
      if (thisObj.hasClass('js_isOpen')) {
        thisObj.removeClass('js_isOpen open');
        outBox.find('input').show();
        outBox.find('button').show();
        $('.js_advancedForm').hide();
      } else {
        thisObj.addClass('js_isOpen open');
        outBox.find('input').hide();
        outBox.find('button').hide();
        $('.js_advancedForm').show();
      }
    });

    // 查看子合伙人
    $('.js_showSecondDealer').click(function(){
        // 获取此一级合伙人的id
        var $url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询子合伙人
        $.ajax({
            url : $url,
            type : "get",
            dataType : 'json',
            error : function () {
              showMsg('此合伙人没有二级合伙人!');
            },
            success : function(res){
                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                    list.find('.js_dealerTitle').html(th.parents('tr').find('td.js_userName').html()+'的子合伙人信息');
                    $('body').append(list);

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();

                    // 说明 存在二级合伙人
                    for (var i in infoList) {
                        var info = $('<tr><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["user_name"]+'</td><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["mobile"]+'</td></tr>');
                        list.find('.js_expressTable').append(info);
                    }

                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });

                } else {
                    alert('此合伙人没有二级合伙人!');
                }
            }
        });

        return false;
    });

  });



  </script>
<div class="float-confirm js_secondDealerList" style="z-index: 20000;display: none; width:auto; height:auto; margin:0px; position : fixed;">
  <div class="float-confirm-con" style="margin:0px 0px;">
    <a class="icon-close js_closeDealerList" href="javascript:void(0);">关闭</a>
    <p style="font-size:18px;color:#23a18b;" class="js_dealerTitle">子合伙人信息</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;max-height:400px;over-flow:hidden;margin-bottom:15px;">
      <table style="line-height:50px;border:1px solid #ccc;margin:0 auto;" class="js_expressTable">
        <tr>
          <th style="width:200px;text-align:center;border:1px solid #ccc">用户名</th>
          <th style="width:200px;text-align:center;border:1px solid #ccc">手机号码</th>
        </tr>

      </table>
      <table style="line-height:50px;display:none;width:400px;line-height:24px;" class="js_refundTable">
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{include_core file="admin/lib/footer.html"}